﻿using UnityEngine;
using System.Collections;

public class PlayerScore : MonoBehaviour
{

    public static int CoinCount = 0;
    public static int LifeCount = 0;
    public static int score = 0;

    public AudioClip coinSound;
    public AudioClip lifeSound;

    // Use this for initialization
    void Start()
    {
	
    }
	
    // Update is called once per frame
    void Update()
    {
	
    }

    void OnCollisionEnter2D(Collision2D other)
    {
        Debug.Log("other.tag: " + other.gameObject.tag);
        if (other.gameObject.tag == "darkCloud")
        {
            //
            //
            var cs = Camera.main.GetComponent<CameraScript>();
            cs.enabled = false;
            transform.localPosition = new Vector3(1000, 1000, 0);
            //GameController.Instance.ShowGameOver(score, CoinCount);
            LifeCount--;
            GameManager.Instance.CheckGameState(LifeCount, CoinCount, score);
        } else if (other.gameObject.tag == "bound")
        {
            var cs = Camera.main.GetComponent<CameraScript>();
            cs.enabled = false;
            transform.localPosition = new Vector3(1000, 1000, 0);
            //GameController.Instance.ShowGameOver(score, CoinCount);
            LifeCount--;
            GameManager.Instance.CheckGameState(LifeCount, CoinCount, score);
        }
    }

    void OnTriggerEnter2D(Collider2D target)
    {
        if (target.tag == "Coin")
        {
            CoinCount++;
            target.gameObject.SetActive(false);
            AudioSource.PlayClipAtPoint(coinSound, transform.position);
            GameController.Instance.SetCoinCount(CoinCount);
            score += 200;
            GameController.Instance.SetScore(score);
        } else if (target.tag == "Life")
        {
            LifeCount++;
            target.gameObject.SetActive(false);
            AudioSource.PlayClipAtPoint(lifeSound, transform.position);
            GameController.Instance.SetLifeCount(LifeCount);

            score += 500;
            GameController.Instance.SetScore(score);
        }
    }
}
